package com.yaowk.system.server.entity;

import com.yaowk.common.db.BaseEntity;
import com.yaowk.common.db.GeneratorNote;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

@Getter
@Setter
@ToString
@Entity
@DynamicInsert
@DynamicUpdate
public class SysRole extends BaseEntity<Long> {

    @GeneratorNote("角色名称")
    private String name;
    @GeneratorNote("描述")
    private String description;
    @GeneratorNote("创建时间")
    @Column(nullable = false, updatable = false)
    @CreationTimestamp
    private Date createTime;
    @GeneratorNote("创建者")
    @Column(nullable = false, updatable = false)
    private Long createUserId;
    @GeneratorNote("状态")
    @Column(nullable = false)
    @ColumnDefault("1")
    private Byte status;

    @ManyToMany
    @JoinTable(name = "sys_role_menu", joinColumns = {@JoinColumn(name = "role_id")}, inverseJoinColumns = {@JoinColumn(name = "menu_id")})
    private Set<SysMenu> menus;
    @ManyToMany(mappedBy = "roles")
    private Set<SysUser> users;


}
